package lumingweihua.future.cn.lumingweihua.ui.message;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.zhusx.core.interfaces.IHttpResult;
import com.zhusx.core.network.HttpRequest;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lumingweihua.future.cn.lumingweihua.R;
import lumingweihua.future.cn.lumingweihua.network.LoadData;
import lumingweihua.future.cn.lumingweihua.network.SimpleHttpListener;
import lumingweihua.future.cn.lumingweihua.ui.BaseCompatActivity;
import lumingweihua.future.cn.lumingweihua.ui.message.domain.CountEntity;

/**
 * Author       zhusx
 * Created      2018/3/15 15:59
 */

public class MessageActivity extends BaseCompatActivity {
    @BindView(R.id.tv_notify_count)
    TextView tvNotifyCount;
    @BindView(R.id.tv_status_count)
    TextView tvStatusCount;
    LoadData<CountEntity> loadData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        ButterKnife.bind(this);
        loadData = new LoadData<>(LoadData.Api.系统通知数量, this);
        loadData._setOnLoadingListener(new SimpleHttpListener<CountEntity>() {
            @Override
            public void onLoadComplete(LoadData.Api api, HttpRequest<Object> request, IHttpResult<CountEntity> t) {
                initView(t.getData());
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        loadData._loadData();
    }

    private void initView(CountEntity en) {
        if (!"0".equals(en.message_num)) {
            tvNotifyCount.setVisibility(View.VISIBLE);
            tvNotifyCount.setText(en.message_num);
        } else {
            tvNotifyCount.setVisibility(View.GONE);
        }
        if (!"0".equals(en.carriage_num)) {
            tvStatusCount.setVisibility(View.VISIBLE);
            tvStatusCount.setText(en.carriage_num);
        } else {
            tvStatusCount.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.layout_notify, R.id.layout_status})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_notify:
                startActivity(new Intent(v.getContext(), SystemNotifyActivity.class));
                break;
            case R.id.layout_status:
                startActivity(new Intent(v.getContext(), StatusActivity.class));
                break;
        }
    }
}
